<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
    />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />

    <title>Document</title>
    <style>
      body,
      html {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
      }
      canvas {
        margin: 50px auto;
        border: 1px solid #ccc;
      }
      div {
        height: 100px;
        border: 1px solid #ccc;
      }
    </style>
  </head>
  <body>
    <canvas id="canvas" style="display: block"></canvas>
    <script>
        var tangram=[
            {p:[{x:0,y:0},{x:800,y:0},{x:400,y:400}],color:"#caff67"},
            {p:[{x:0,y:0},{x:400,y:400},{x:0,y:800}],color:"#67beef"},
            {p:[{x:800,y:0},{x:800,y:400},{x:600,y:600},{x:600,y:200}],color:"#ef3d61"},
            {p:[{x:600,y:200},{x:600,y:600},{x:400,y:400}],color:"#FDEA11"},
            {p:[{x:400,y:400},{x:600,y:600},{x:400,y:800},{x:200,y:600}],color:"#a594c0"},
            {p:[{x:200,y:600},{x:400,y:800},{x:0,y:800}],color:"#fa8ccc"},
            {p:[{x:800,y:400},{x:800,y:800},{x:400,y:800}],color:"#f6ca29"}
        ]
      window.onload = function () {
        const canvas = document.querySelector("#canvas");
        canvas.width = 800;
        canvas.height = 800;
        const context = canvas.getContext("2d");
        tangram.forEach((item, i) => {
          draw(item.p, item.color);
        });
        function draw(p, color) {
          context.beginPath();
          context.moveTo(p[0].x, p[0].y);
            for (let i = 1; i < p.length; i++) {
                context.lineTo(p[i].x, p[i].y)
            }
          context.closePath();
          context.fillStyle = color;
          context.fill();
          context.strokeStyle='black'
          context.lineWidth=5
            context.stroke();

        }

      };
    </script>
  </body>
</html>
